package com.hnkywl.sts.dao.tjbb;

import com.hnkywl.sts.entity.zjgl.Bzjyj;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.springframework.stereotype.Repository;
import java.util.*;

/**
 * Created by HL on 2015/9/20.
 */
@Repository
public class BzjyjDao extends SimpleHibernateTemplate<Bzjyj, Long> {
    /**
     * 查询所有的保证金预警
     * @param htbm
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<Bzjyj> findBzjyjList(String htbm, int pageNo, int pageSize) {
        String hql = null;
        List<Object> param = new ArrayList<Object>();
        StringBuilder condition = new StringBuilder();
        Page<Bzjyj> page = new Page<Bzjyj>(pageNo, pageSize, 0);
        //==============条件拼接===============
        if (htbm != null && !htbm.isEmpty()) {
            condition.append(" cght.htbm like ? ");
            param.add("%" + htbm.trim() + "%");
        }

        //==============记录数量===============
        hql = "select count(*) from Bzjyj";
        if (condition.length() != 0)
            hql = hql + " where " + condition;
        Long c = null;
        if (param.size() != 0) {
            c = (Long) findUnique(hql, param.toArray());
            page.setTotalCount(c.intValue());
        } else {
            c = (Long) findUnique(hql);
            page.setTotalCount(c.intValue());
        }
        if (c == 0)
            return page;
        //==============查询结果===============
        hql = "from Bzjyj ";
        if (condition.length() != 0)
            hql = hql + " where " + condition;
        if (param.size() != 0)
            return find(page, hql, param.toArray());
        return find(page, hql);
    }


}
